﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Common.ViewModels;
using DynamicData;

namespace PlatingLineUI.Windows
{
    /// <summary>
    /// 配方Window.xaml 的交互逻辑
    /// </summary>
    public partial class 配方Window : Window
    {
        public 配方Window()
        {
            InitializeComponent();
            this.DataContext = ProductLine.Instance;
        }

        private void BtnAdd配方_Click(object sender, RoutedEventArgs e)
        {
            ProductLine.Instance.配方s.Add(new 配方() { Name = $"配方{ProductLine.Instance.配方s.Count + 1}" });
        }

        private void BtnDelete配方_Click(object sender, RoutedEventArgs e)
        {
            ProductLine.Instance.配方s.Remove(ProductLine.Instance.Select配方);
        }

        private void Btn添加配方_OnClick(object sender, RoutedEventArgs e)
        {
            var select = ProductLine.Instance.Select配方;
            if (select == null)
            {
                return;
            }

            if (cmb配方.SelectedValue is 配方 pf)
            {
                select.工位类型s.Add(pf);
            }
        }

        private void Btn添加工艺_OnClick(object sender, RoutedEventArgs e)
        {
            var select = ProductLine.Instance.Select配方;
            if (select == null)
            {
                return;
            }

            if (cmb工艺.SelectedValue is 工位类型 gy)
            {
                select.工位类型s.Add(gy);
            }
        }

        private void MenuItem_OnClick(object sender, RoutedEventArgs e)
        {
            FrameworkElement frameworkElement=sender as FrameworkElement;
            if (frameworkElement == null)
            {
                return;
            }

            if (frameworkElement.DataContext == null)
            {
                return;
            }

            var select = ProductLine.Instance.Select配方;
            if (select == null)
            {
                return;
            }

            if (frameworkElement.DataContext is 工位类型 gwlx)
            {
                select.工位类型s.Remove(gwlx);
            }
        }
    }
}
